package com.team.app.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.team.app.dao.AuthDao;
import com.team.app.enums.ObjectType;
import com.team.app.model.Auth;
import com.team.app.model.Company;
import com.team.app.util.ConvertUtil;


@Service
public class AuthServiceImpl implements AuthService{
	@Autowired
    private AuthDao authDao;     

	@Override
	@Transactional
	public Long create(Auth obj) {
		// TODO Auto-generated method stub
		return authDao.create(obj);
	}
	
	@Transactional
	public Long create(Auth auth , Company comp, Auth loginAuth) {
		auth.setAccountName(comp.getCompanyEmail());
		auth.setPassword(ConvertUtil.md5Hash("abc@12345"));
		auth.setRoleId(99L);
		auth.setCompanyId(comp.getCompanyId());
		auth.setObjectType(ObjectType.TYPE_MEMBER.getKey());			
		auth.setApproveBy(loginAuth.getAccountName());
		auth.setApproveDate(new Date());
		auth.setActive(1L);
		return authDao.create(auth);
	}

	@Override
	@Transactional
	public void edit(Auth obj) {
		// TODO Auto-generated method stub
		authDao.edit(obj);
	}

	@Override
	@Transactional
	public void remove(Auth obj) {
		// TODO Auto-generated method stub
		authDao.remove(obj);
	}

	@Override
	@Transactional
	public Auth find(Object id) {
		// TODO Auto-generated method stub
		return authDao.find(id);
	}

	@Override
	@Transactional
	public List<Auth> findAll() {
		// TODO Auto-generated method stub
		return authDao.findAll();
	}

	@Override
	@Transactional
	public List<Auth> findRange(int[] range) {
		// TODO Auto-generated method stub
		return authDao.findRange(range);
	}

	@Override
	@Transactional
	public Long count() {
		// TODO Auto-generated method stub
		return authDao.count();
	}

	@Override
	@Transactional
	public Auth checkLogin(String accuntName, String password) {
		// TODO Auto-generated method stub
		return authDao.checkLogin(accuntName,password);
	}

	@Override
	@Transactional
	public List<Auth> findAll(Long parentId,Long roleId,String accountName,Long active) {
		// TODO Auto-generated method stub
		return authDao.findAll(parentId,roleId,accountName,active);
	}

	@Override
	@Transactional
	public Auth find(String accuntName) {
		// TODO Auto-generated method stub
		return authDao.find(accuntName);
	}

	@Override
	@Transactional
	public List<Auth> findByCompanyAll(Long parentId,Long companyId) {
		// TODO Auto-generated method stub
		return authDao.findByCompanyAll(parentId,companyId);
	}

	@Override
	@Transactional
	public List<Auth> findByCompanyAll(Long companyId) {
		// TODO Auto-generated method stub
		return authDao.findByCompanyAll(companyId);
	}
}
